#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <iostream>
#include <chrono>

int main(int argc, char* argv[])
{

    int fd = open("/dev/hello", O_RDWR, S_IRUSR|S_IWUSR);
    if(fd != -1)
    {
        void* paddr = nullptr;
        int res = ioctl(fd, 0xC0506D14, (unsigned long)&paddr);;
        std::cout<< "alloc memory: " << paddr << std::endl;
        
        int testCnt = (1<<20) / 4;
        std::chrono::steady_clock::time_point startTime = std::chrono::steady_clock::now();
        for (int i = 0; i < 10000; i++)
        {
            int* pTestAddr = static_cast<int*>(paddr);
            for (int j = 0; j < testCnt; j++)
            {
                *pTestAddr += 1;
                ++pTestAddr;
            }
        }
        std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
        auto time_span = std::chrono::duration_cast<std::chrono::microseconds>(now - startTime);
		auto time_count = time_span.count();
        std::cout<< "timecount: " << time_count << std::endl;

	    close(fd);
    }
    else
    {
        perror("Failed at open():");
    }
    return 0;
}

